package com.hdu.controller;


import com.hdu.entity.Chat;
import com.hdu.pojo.Friend;
import com.hdu.pojo.Result;
import com.hdu.service.IChatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 聊天记录实体类 前端控制器
 * </p>
 *
 * @author xiaobai
 * @since 2024-05-20
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "聊天管理接口")
@RequestMapping("/chat")
public class ChatController {

    private final IChatService chatService;

    @ApiOperation("获取用户聊天信息")
    @GetMapping
    public Result<List<Chat>> page(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pageSize,
                                   String id, String sender) {
        log.info("分页查询, 参数: {},{},{},{},", page, pageSize, id, sender);
        //调用service分页查询
        return Result.success(chatService.page(page, pageSize, id, sender));
    }

    @ApiOperation("获取用户好友列表")
    @GetMapping("/friend")
    public Result<List<Friend>> friend(String tID) {
        log.info("聊天好友查询, 参数: {}", tID);
        return Result.success(chatService.friend(tID));
    }

}
